package com.jcl.core.security.entity;

/**
 * @ClassName ResultEnum
 * @Author yyliu
 * @Date 2018/12/21 9:24
 * @Version 1.0
 **/
public enum ResultEnum {


    SUCCESS(200, "成功"),
    FAILURE(300, "失败"),
    USER_LOGIN_FAILED(302, "用户账号或密码错误"),
    USER_LOGIN_SUCCESS(303, "用户登录成功"),
    USER_LOGOUT_SUCCESS(305, "用户登出成功"),
    TOKEN_IS_BLACKLIST(306, "此token为黑名单"),
    LOGIN_IS_OVERDUE(307, "登录已失效"),
    USER_NEED_AUTHORITIES(401, "用户未登录"),
    USER_NO_ACCESS(403, "用户无权访问"),
    ;

    private Integer code;

    private String message;

    ResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultEnum parse(int code) {
        ResultEnum[] values = values();
        for (ResultEnum value : values) {
            if (value.getCode() == code) {
                return value;
            }
        }
        throw new RuntimeException("Unknown code of ResultEnum");
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
